package main

import "fmt"

func main() {
	//object
	//yangxu: 18
	//zhaosang: 19
	//mahong: 20
	//teacherAge := make(map[keyType]valueType)
	teacherAge := make(map[string]int)
	fmt.Println(teacherAge) //map[]
	teacherAge["yangxu"] = 18
	teacherAge["zhaosang"] = 19
	teacherAge["mahong"] = 20
	teacherAge["yangxu"] = 22
	fmt.Println(teacherAge) //无序

	//在声明变量的时候直接进行赋值操作
	teacherAge2 := map[string]int{
		"yangxu":   18,
		"zhaosang": 19,
		"mahong":   20,
	}
	fmt.Println("teacherAge2 is : ", teacherAge2)

	for k, v := range teacherAge {
		fmt.Println(k, v)
	}

	//使用var 赋值
	var teacherAddress map[string]string
	teacherAddress = make(map[string]string)
	teacherAddress["yangxu"] = "lianyungang"
	teacherAddress["mahong"] = "yancheng"
	teacherAddress["zhaosang"] = "pingdingshan"

	fmt.Println(teacherAddress)
	//对象的增删改查
	fmt.Println("查询yangxu老师的地址", teacherAddress["yangxu"])
	searchName := "mahong"
	fmt.Printf("查询老师：%s的地址：%s\n", searchName, teacherAddress["mahong"])
	fmt.Println("不存在的: ", teacherAddress["hmk2020"])
	address, ok := teacherAddress["mahong"]
	if ok {
		fmt.Println("可以查询到", address)
		fmt.Println(ok)
	} else {
		fmt.Println("查不到")
	}
	//删除
	delete(teacherAddress, "yangxu")
	fmt.Println(teacherAddress)
}
